﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace Fish_Atlantis.ProfessorPanel
{
    public partial class RiskForm : System.Web.UI.Page
    {
        int x;//数据库行数
        int y = 13;
        int a = DateTime.Now.Month;
        //string connStr = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
            string connStr = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(connStr);
            conn.Open();
            string sq = "select DISTINCT FisheryName from Fishery;";
            try
            {
                SqlDataAdapter da = new SqlDataAdapter(sq, conn);
                DataSet ds = new DataSet();

                da.Fill(ds);
                DataTable dt = ds.Tables[0];

                x = dt.Rows.Count+1;
                for (int i = 0; i < x; i++)
                {
                    TableRow tr = new TableRow();
                    Table1.Rows.Add(tr);

                    for (int j = 0; j < y; j++)
                    {
                        TableCell td = new TableCell();
                        tr.Cells.Add(td);
                        //td.Text = "";
                    }
                }


                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Table1.Rows[i+1].Cells[0].Text=dt.Rows[i]["FisheryName"].ToString();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }

            Table1.Rows[0].Cells[1].Text = "一月";
            Table1.Rows[0].Cells[2].Text = "二月";
            Table1.Rows[0].Cells[3].Text = "三月";
            Table1.Rows[0].Cells[4].Text = "四月";
            Table1.Rows[0].Cells[5].Text = "五月";
            Table1.Rows[0].Cells[6].Text = "六月";
            Table1.Rows[0].Cells[7].Text = "七月";
            Table1.Rows[0].Cells[8].Text = "八月";
            Table1.Rows[0].Cells[9].Text = "九月";
            Table1.Rows[0].Cells[10].Text = "十月";
            Table1.Rows[0].Cells[11].Text = "十一月";
            Table1.Rows[0].Cells[12].Text = "十二月";

            try
            {
                for (int i = 1; i<x; i++)
                {
                    string sqq = "select Risk_Rank from Risk,Fishery WHERE Risk.FisheryID=Fishery.FisheryID AND Risk.Month='"+a+"'AND Fishery.FisheryName='"+Table1.Rows[i].Cells[0].Text+"';";
                    SqlDataAdapter daa = new SqlDataAdapter(sqq, conn);
                    DataSet dss = new DataSet();

                    daa.Fill(dss);
                    DataTable dtt = dss.Tables[0];
                    if(dss.Tables[0].Rows.Count>0)
                    Table1.Rows[i].Cells[a].Text = dtt.Rows[0]["Risk_Rank"].ToString();
                    else
                        Table1.Rows[i].Cells[a].Text ="未评级";

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }
        }
        

    }
}